69template <
typename Derived>
70inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
skew(
const Eigen::MatrixBase<Derived>& _v)
74 typedef typename Derived::Scalar T;
76 Eigen::Matrix<T, 3, 3> sk;
78 sk << (T)0.0, -_v(2), +_v(1), +_v(2), (T)0.0, -_v(0), -_v(1), +_v(0), (T)0.0;
88template <
typename Derived>
89inline Eigen::Matrix<typename Derived::Scalar, 3, 1>
vee(
const Eigen::MatrixBase<Derived>& _m)
93 typedef typename Derived::Scalar T;
95 return (Eigen::Matrix<T, 3, 1>() << _m(2, 1), _m(0, 2), _m(1, 0)).finished();
108template <
typename Derived>
109inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
q2R(
const Eigen::QuaternionBase<Derived>& _q)
119template <
typename Derived>
120inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
q2R(
const Eigen::MatrixBase<Derived>& _q)
123 Eigen::Quaternion<typename Derived::Scalar> q(_q(3), _q(0), _q(1), _q(2));
132template <
typename Derived>
133inline Eigen::Quaternion<typename Derived::Scalar>
R2q(
const Eigen::MatrixBase<Derived>& _R)
137 return Eigen::Quaternion<typename Derived::Scalar>(_R);
145inline Eigen::Quaternion<typename D::Scalar>
e2q(
const Eigen::MatrixBase<D>& _euler)
149 typedef typename D::Scalar T;
151 const Eigen::AngleAxis<T> ax = Eigen::AngleAxis<T>(_euler(0), Eigen::Matrix<T, 3, 1>::UnitX());
152 const Eigen::AngleAxis<T> ay = Eigen::AngleAxis<T>(_euler(1), Eigen::Matrix<T, 3, 1>::UnitY());
153 const Eigen::AngleAxis<T> az = Eigen::AngleAxis<T>(_euler(2), Eigen::Matrix<T, 3, 1>::UnitZ());
155 return Eigen::Quaternion<T>(az * ay * ax);
162template <
typename Derived>
163inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
e2R(
const Eigen::MatrixBase<Derived>& _e)
167 return e2q(_e).matrix();
170template <
typename Derived>
171inline typename Eigen::Matrix<typename Derived::Scalar, 3, 1>
R2e(
const Eigen::MatrixBase<Derived>& _R)
173 Eigen::Matrix<typename Derived::Scalar, 3, 1> e;
175 e(0) =
atan2(_R(2, 1), _R(2, 2));
176 e(1) =
atan2(-_R(2, 0),
sqrt(_R(0, 0) * _R(0, 0) + _R(1, 0) * _R(1, 0)));
177 e(2) =
atan2(_R(1, 0), _R(0, 0));
182template <
typename Derived>
183inline typename Eigen::Matrix<typename Derived::Scalar, 3, 1>
q2e(
const Eigen::MatrixBase<Derived>& _q)
185 typedef typename Derived::Scalar T;
186 Eigen::Matrix<T, 3, 1> e;
188 const double& w = _q(3);
189 const double& x = _q(0);
190 const double& y = _q(1);
191 const double& z = _q(2);
203 double r00 = T(1) - T(2) * (yy + zz);
204 double r10 = T(2) * (xy + wz);
205 double r20 = T(2) * (xz - wy);
206 double r21 = T(2) * (yz + wx);
207 double r22 = T(1) - T(2) * (xx + yy);
209 e(0) =
atan2(r21, r22);
210 e(1) =
atan2(-r20,
sqrt(r00 * r00 + r10 * r10));
211 e(2) =
atan2(r10, r00);
216template <
typename Derived>
217inline typename Eigen::Matrix<typename Derived::Scalar, 3, 1>
q2e(
const Eigen::QuaternionBase<Derived>& _q)
219 return q2e(_q.coeffs());
222template <
typename Derived>
223inline typename Eigen::MatrixBase<Derived>::Scalar
getYaw(
const Eigen::MatrixBase<Derived>& _M)
226 if (_M.rows() == 3 and _M.cols() == 3)
return std::atan2(_M(1, 0), _M(0, 0));
229 if (_M.rows() == 4 and _M.cols() == 1)
231 typedef typename Derived::Scalar T;
232 const double& w = _M(3, 0);
233 const double& x = _M(0, 0);
234 const double& y = _M(1, 0);
235 const double& z = _M(2, 0);
236 return atan2(T(2) * (x * y + w * z), T(1) - T(2) * (y * y + z * z));
240 assert(
false &&
"getYaw wrong input size. Should be 3x3 matrix (rotation matrix) or 4d vector (quaternion).");
243template <
typename Derived>
244inline typename Eigen::QuaternionBase<Derived>::Scalar
getYaw(
const Eigen::QuaternionBase<Derived>& _q)
246 return getYaw(_q.coeffs());
257template <
typename Derived>
258inline Eigen::Quaternion<typename Derived::Scalar>
exp_q(
const Eigen::MatrixBase<Derived>& _v)
266 typedef typename Derived::Scalar T;
268 T angle_squared = _v.squaredNorm();
269 T angle =
sqrt(angle_squared);
273 return Eigen::Quaternion<T>(Eigen::AngleAxis<T>(angle, _v.normalized()));
277 return Eigen::Quaternion<T>((T)1.0, _v(0, 0) / (T)2, _v(1, 0) / (T)2, _v(2, 0) / (T)2);
286template <
typename Derived>
287inline Eigen::Matrix<typename Derived::Scalar, 3, 1>
log_q(
const Eigen::QuaternionBase<Derived>& _q)
297 typedef typename Derived::Scalar T;
299 Eigen::Matrix<T, 3, 1> vec = _q.vec();
300 const T sin_angle_squared = vec.squaredNorm();
303 const T sin_angle =
sqrt(sin_angle_squared);
304 const T& cos_angle = _q.w();
316 T(2.0) * ((cos_angle < T(0.0)) ?
atan2(-sin_angle, -cos_angle) :
atan2(sin_angle, cos_angle));
317 const T k = two_angle / sin_angle;
332template <
typename Derived>
333inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
exp_R(
const Eigen::MatrixBase<Derived>& _v)
339 typedef typename Derived::Scalar T;
341 T angle_squared = _v.squaredNorm();
342 T angle =
sqrt(angle_squared);
345 return Eigen::AngleAxis<T>(angle, _v.normalized()).toRotationMatrix();
347 return Eigen::Matrix<T, 3, 3>::Identity() +
skew(_v);
355template <
typename Derived>
356inline Eigen::Matrix<typename Derived::Scalar, 3, 1>
log_R(
const Eigen::MatrixBase<Derived>& _R)
366template <
typename Derived>
367inline Eigen::Quaternion<typename Derived::Scalar>
v2q(
const Eigen::MatrixBase<Derived>& _v)
377template <
typename Derived>
378inline Eigen::Matrix<typename Derived::Scalar, 3, 1>
q2v(
const Eigen::QuaternionBase<Derived>& _q)
388template <
typename Derived>
389inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
v2R(
const Eigen::MatrixBase<Derived>& _v)
399template <
typename Derived>
400inline Eigen::Matrix<typename Derived::Scalar, 3, 1>
R2v(
const Eigen::MatrixBase<Derived>& _R)
422template <
typename Derived>
423inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
jac_SO3_right(
const Eigen::MatrixBase<Derived>& _theta)
431 typedef typename Derived::Scalar T;
433 T theta2 = _theta.squaredNorm();
434 Eigen::Matrix<T, 3, 3> W(
skew(_theta));
436 return Eigen::Matrix<T, 3, 3>::Identity() - (T)0.5 * W;
437 T theta =
sqrt(theta2);
438 Eigen::Matrix<T, 3, 3> M1, M2;
439 M1.noalias() = ((T)1 -
cos(theta)) / theta2 * W;
440 M2.noalias() = (theta -
sin(theta)) / (theta2 * theta) * (W * W);
441 return Eigen::Matrix<T, 3, 3>::Identity() - M1 + M2;
462template <
typename Derived>
463inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
jac_SO3_right_inv(
const Eigen::MatrixBase<Derived>& _theta)
471 typedef typename Derived::Scalar T;
473 T theta2 = _theta.squaredNorm();
474 Eigen::Matrix<T, 3, 3> W(
skew(_theta));
476 return Eigen::Matrix<T, 3, 3>::Identity() + (T)0.5 * W;
477 T theta =
sqrt(theta2);
478 Eigen::Matrix<T, 3, 3> M;
479 M.noalias() = ((T)1.0 / theta2 - ((T)1.0 +
cos(theta)) / ((T)2.0 * theta *
sin(theta))) * (W * W);
480 return Eigen::Matrix<T, 3, 3>::Identity() + (T)0.5 * W + M;
496template <
typename Derived>
497inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
jac_SO3_left(
const Eigen::MatrixBase<Derived>& _theta)
505 typedef typename Derived::Scalar T;
507 T theta2 = _theta.squaredNorm();
508 Eigen::Matrix<T, 3, 3> W(
skew(_theta));
510 return Eigen::Matrix<T, 3, 3>::Identity() - (T)0.5 * W;
511 T theta =
sqrt(theta2);
512 Eigen::Matrix<T, 3, 3> M1, M2;
513 M1.noalias() = ((T)1 -
cos(theta)) / theta2 * W;
514 M2.noalias() = (theta -
sin(theta)) / (theta2 * theta) * (W * W);
515 return Eigen::Matrix<T, 3, 3>::Identity() + M1 + M2;
535template <
typename Derived>
536inline Eigen::Matrix<typename Derived::Scalar, 3, 3>
jac_SO3_left_inv(
const Eigen::MatrixBase<Derived>& _theta)
544 typedef typename Derived::Scalar T;
546 T theta2 = _theta.squaredNorm();
547 Eigen::Matrix<T, 3, 3> W(
skew(_theta));
549 return Eigen::Matrix<T, 3, 3>::Identity() + (T)0.5 * W;
550 T theta =
sqrt(theta2);
551 Eigen::Matrix<T, 3, 3> M;
552 M.noalias() = ((T)1.0 / theta2 - ((T)1.0 +
cos(theta)) / ((T)2.0 * theta *
sin(theta))) * (W * W);
553 return Eigen::Matrix<T, 3, 3>::Identity() - (T)0.5 * W + M;
556template <
typename D1,
typename D2,
typename D3,
typename D4,
typename D5>
557inline void compose(
const Eigen::QuaternionBase<D1>& _q1,
558 const Eigen::QuaternionBase<D2>& _q2,
559 Eigen::QuaternionBase<D3>& _q_comp,
560 Eigen::MatrixBase<D4>& _J_comp_q1,
561 Eigen::MatrixBase<D5>& _J_comp_q2)
568 _J_comp_q1 =
q2R(_q2.conjugate());
569 _J_comp_q2.setIdentity();
572template <
typename D1,
typename D2,
typename D3,
typename D4,
typename D5>
573inline void between(
const Eigen::QuaternionBase<D1>& _q1,
574 const Eigen::QuaternionBase<D2>& _q2,
575 Eigen::QuaternionBase<D3>& _q_between,
576 Eigen::MatrixBase<D4>& _J_between_q1,
577 Eigen::MatrixBase<D5>& _J_between_q2)
582 _q_between = _q1.conjugate() * _q2;
584 _J_between_q1 = -
q2R(_q2.conjugate() * _q1);
585 _J_between_q2.setIdentity();
588template <
typename D1,
typename D2>
589inline Eigen::Quaternion<typename D1::Scalar>
plus_right(
const Eigen::QuaternionBase<D1>& q,
590 const Eigen::MatrixBase<D2>& v)
596template <
typename D1,
typename D2>
597inline Eigen::Matrix<typename D2::Scalar, 3, 1>
minus_right(
const Eigen::QuaternionBase<D1>& q1,
598 const Eigen::QuaternionBase<D2>& q2)
600 return log_q(q1.conjugate() * q2);
603template <
typename D1,
typename D2>
604inline Eigen::Quaternion<typename D1::Scalar>
plus_left(
const Eigen::MatrixBase<D2>& v,
605 const Eigen::QuaternionBase<D1>& q)
611template <
typename D1,
typename D2>
612inline Eigen::Matrix<typename D2::Scalar, 3, 1>
minus_left(
const Eigen::QuaternionBase<D1>& q1,
613 const Eigen::QuaternionBase<D2>& q2)
615 return log_q(q2 * q1.conjugate());
618template <
typename D1,
typename D2>
619inline Eigen::Quaternion<typename D1::Scalar>
plus(
const Eigen::QuaternionBase<D1>& q,
const Eigen::MatrixBase<D2>& v)
624template <
typename D1,
typename D2>
625inline Eigen::Matrix<typename D2::Scalar, 3, 1>
minus(
const Eigen::QuaternionBase<D1>& q1,
626 const Eigen::QuaternionBase<D2>& q2)
631template <
typename D1,
typename D2>
632inline Eigen::Matrix<typename D2::Scalar, 3, 1>
diff(
const Eigen::QuaternionBase<D1>& q1,
633 const Eigen::QuaternionBase<D2>& q2)
635 return minus(q1, q2);
const double EPS_SMALL
Definition: wolf.h:76
Jet< double, N > remainder(const Jet< double, N > &_x, long double _y)
Definition: wolf_jet.h:31
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:641
Jet< T, N > atan2(const Jet< T, N > &g, const Jet< T, N > &f)
Definition: jet.h:1167
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:617
Jet< T, N > cos(const Jet< T, N > &f)
Definition: jet.h:626
Definition: capture_base.h:23
Eigen::Matrix< typename Derived::Scalar, 3, 3 > q2R(const Eigen::QuaternionBase< Derived > &_q)
quaternion to rotation matrix conversion
Definition: rotations.h:109
Eigen::Matrix< typename Derived::Scalar, 3, 1 > q2e(const Eigen::MatrixBase< Derived > &_q)
Definition: rotations.h:183
Eigen::Matrix< typename D2::Scalar, 3, 1 > minus(const Eigen::QuaternionBase< D1 > &q1, const Eigen::QuaternionBase< D2 > &q2)
Definition: rotations.h:625
Eigen::Quaternion< typename Derived::Scalar > v2q(const Eigen::MatrixBase< Derived > &_v)
Rotation vector to quaternion conversion.
Definition: rotations.h:367
Eigen::Matrix< typename Derived::Scalar, 3, 3 > jac_SO3_right_inv(const Eigen::MatrixBase< Derived > &_theta)
Compute Jrinv (inverse of Right Jacobian which corresponds to the jacobian of log) Right Jacobian for...
Definition: rotations.h:463
T pi2pi(const T &_angle)
Return angle between -pi and pi This implementation uses std::remainder which makes it incompatible f...
Definition: rotations.h:34
Eigen::Matrix< typename Derived::Scalar, 3, 1 > R2e(const Eigen::MatrixBase< Derived > &_R)
Definition: rotations.h:171
Eigen::Quaternion< typename Derived::Scalar > exp_q(const Eigen::MatrixBase< Derived > &_v)
Quaternion exponential map.
Definition: rotations.h:258
Eigen::Matrix< typename Derived::Scalar, 3, 3 > jac_SO3_left(const Eigen::MatrixBase< Derived > &_theta)
Compute Jl (Left Jacobian) Left Jacobian for exp map in SO(3) - equation (10.86) and following equati...
Definition: rotations.h:497
Eigen::Matrix< typename D2::Scalar, 3, 1 > minus_left(const Eigen::QuaternionBase< D1 > &q1, const Eigen::QuaternionBase< D2 > &q2)
Definition: rotations.h:612
Eigen::Matrix< typename D2::Scalar, 3, 1 > diff(const Eigen::QuaternionBase< D1 > &q1, const Eigen::QuaternionBase< D2 > &q2)
Definition: rotations.h:632
T toDeg(const T rad)
Conversion to degrees.
Definition: rotations.h:56
Eigen::Quaternion< typename D1::Scalar > plus_right(const Eigen::QuaternionBase< D1 > &q, const Eigen::MatrixBase< D2 > &v)
Definition: rotations.h:589
Eigen::Matrix< typename Derived::Scalar, 3, 3 > v2R(const Eigen::MatrixBase< Derived > &_v)
Rotation vector to rotation matrix conversion.
Definition: rotations.h:389
Eigen::Matrix< typename Derived::Scalar, 3, 1 > q2v(const Eigen::QuaternionBase< Derived > &_q)
Quaternion to rotation vector conversion.
Definition: rotations.h:378
Eigen::Matrix< typename Derived::Scalar, 3, 3 > jac_SO3_right(const Eigen::MatrixBase< Derived > &_theta)
Compute Jr (Right Jacobian) Right Jacobian for exp map in SO(3) - equation (10.86) and following equa...
Definition: rotations.h:423
Eigen::Matrix< typename Derived::Scalar, 3, 3 > exp_R(const Eigen::MatrixBase< Derived > &_v)
Rotation matrix exponential map.
Definition: rotations.h:333
Eigen::Matrix< typename D2::Scalar, 3, 1 > minus_right(const Eigen::QuaternionBase< D1 > &q1, const Eigen::QuaternionBase< D2 > &q2)
Definition: rotations.h:597
Eigen::Matrix< typename Derived::Scalar, 3, 1 > log_q(const Eigen::QuaternionBase< Derived > &_q)
Quaternion logarithmic map.
Definition: rotations.h:287
Eigen::Quaternion< typename D::Scalar > e2q(const Eigen::MatrixBase< D > &_euler)
Euler angles to quaternion.
Definition: rotations.h:145
T toRad(const T deg)
Conversion to radians.
Definition: rotations.h:45
Eigen::Matrix< typename Derived::Scalar, 3, 1 > R2v(const Eigen::MatrixBase< Derived > &_R)
Rotation matrix to rotation vector conversion.
Definition: rotations.h:400
Eigen::Matrix< typename Derived::Scalar, 3, 1 > log_R(const Eigen::MatrixBase< Derived > &_R)
Rotation matrix logarithmic map.
Definition: rotations.h:356
Eigen::Quaternion< typename Derived::Scalar > R2q(const Eigen::MatrixBase< Derived > &_R)
rotation matrix to quaternion conversion
Definition: rotations.h:133
Eigen::Quaternion< typename D1::Scalar > plus_left(const Eigen::MatrixBase< D2 > &v, const Eigen::QuaternionBase< D1 > &q)
Definition: rotations.h:604
Eigen::Matrix< typename Derived::Scalar, 3, 3 > jac_SO3_left_inv(const Eigen::MatrixBase< Derived > &_theta)
Compute Jl_inv (inverse of Left Jacobian which corresponds to the jacobian of log) Left Jacobian for ...
Definition: rotations.h:536
Eigen::Quaternion< typename D1::Scalar > plus(const Eigen::QuaternionBase< D1 > &q, const Eigen::MatrixBase< D2 > &v)
Definition: rotations.h:619
Eigen::Matrix< typename Derived::Scalar, 3, 1 > vee(const Eigen::MatrixBase< Derived > &_m)
Inverse of skew symmetric matrix.
Definition: rotations.h:89
Eigen::Matrix< typename Derived::Scalar, 3, 3 > e2R(const Eigen::MatrixBase< Derived > &_e)
Euler angles to rotation matrix.
Definition: rotations.h:163
void between(const Eigen::QuaternionBase< D1 > &_q1, const Eigen::QuaternionBase< D2 > &_q2, Eigen::QuaternionBase< D3 > &_q_between, Eigen::MatrixBase< D4 > &_J_between_q1, Eigen::MatrixBase< D5 > &_J_between_q2)
Definition: rotations.h:573
Eigen::Matrix< typename Derived::Scalar, 3, 3 > skew(const Eigen::MatrixBase< Derived > &_v)
Skew symmetric matrix.
Definition: rotations.h:70
Eigen::MatrixBase< Derived >::Scalar getYaw(const Eigen::MatrixBase< Derived > &_M)
Definition: rotations.h:223
void compose(const Eigen::QuaternionBase< D1 > &_q1, const Eigen::QuaternionBase< D2 > &_q2, Eigen::QuaternionBase< D3 > &_q_comp, Eigen::MatrixBase< D4 > &_J_comp_q1, Eigen::MatrixBase< D5 > &_J_comp_q2)
Definition: rotations.h:557
static void check(const T &t)
Assert matrix size dynamically or statically.
Definition: wolf.h:187
#define M_TORAD
Definition: wolf.h:68
#define M_TODEG
Definition: wolf.h:69